package com.shujia.base;

import com.shujia.utils.HBaseUtil;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.util.Bytes;

import java.util.Scanner;

/**
 *  测试刚刚分析出的文科一班的学生
 */
public class HBasePracticeDemo2 {
    public static void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入您要获取前几的学生：");
        int i = sc.nextInt();
        getTopNStudent(i);

    }

    public static void getTopNStudent(int number) throws Exception{
        ResultScanner results = HBaseUtil.scanDataReturn("clazzWenOne", number);
        for (Result result : results) {
            String rk = Bytes.toString(result.getRow());
            String[] strings = rk.split("-");
            int score = 1000-Integer.parseInt(strings[0]);
            String id = strings[1];
            String name = Bytes.toString(result.getValue(Bytes.toBytes("info"), Bytes.toBytes("name")));
            String clazz = Bytes.toString(result.getValue(Bytes.toBytes("info"), Bytes.toBytes("clazz")));
            System.out.println("学号:" + id + "\t姓名:" + name + "\t班级:" + clazz + "\t总分:" + score);
        }
    }
}
